package cn.rentaotao.spring.config;

import com.mysql.cj.jdbc.Driver;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;

import javax.sql.DataSource;
import java.sql.SQLException;

/**
 * @author rtt
 * @date 2022/5/17 13:38
 */
@Configuration
public class DataSourceConfig {

    @Value("jdbc.url")
    String url;

    @Value("jdbc.username")
    String username;

    @Value("jdbc.password")
    String password;

    @Bean
    public DataSource dataSource() throws SQLException {
        return new SimpleDriverDataSource(new Driver(), url, username, password);
    }
}
